To construct expressions, primary operands like values
and variables are mixed with operators. The number of operands (one, two or more)
is indicated by adjectives like unary, binary, ternary and n-ary.
The position of the operator with respect to its operands
is indicated by adjectives like binary, prefix, postfix and bifix.
Operators that take both a left and right operand are called
binary operators. Those that take more than 2 operands
with n-1 operator symbols between n operands
are called n-ary operators.
Those that take just one operand are called
unary operators. A unary operator can come before or after the operand; these are called prefix and postfix operators.
A unary operator can be composed of two symbols, with the operand between them; these are called
bifix unary operators.
There is a third class of operators, called construct operators, that use multi-part notations
whose parts are interleaved with two or more operator symbols.
They
are described in their own sections of this guide: Integrals and Derivatives §2.8.1,
Series Generators §2.8.3.1,
Piecewise Expressions §2.8.2,
and Transforms §3.3.5, §9.1.
Figure 2.21 Expression
2.4.1 Binary operators
Examples of binary operators are
a+b
and
x^y.
Binary operators are categorized by precedence (§2.2).
Recall that when there is more than one operator in an expression,
operators with higher precedence are associated with adjacent operands before
operators with lower precedence. That is, a+b*c is
parsed as a+.[(b⋅c)]. Operators with the same precedence
are associated in left-to-right order. Thus a+b-c+d
is parsed as .[((a+b)-c)+d].
The only exception is exponentiation, which associates in right to left order.
Hence
a^b^c is parsed as a^.[(b^c)].
See §2.10.3 for a summary of binary operations.
Figure 2.22 Binary operators and precedence
2.4.2 n-ary Operators
Mathematicians often use a notation like a<x<b to
indicate x is between a and b[1].
This is an example of an n-ary operator.
Although a binary operator could be considered to be an n-ary operator with n=2,
the discussion here is concerned with binary operators that perform comparisons and can be chained together.
The expression a<x<b can be unchained to mean
(a<x)∧(x<b).
A longer unchained expression like (a<b)∧(b<c)∧(c<d) can
be written in chained form a<b<c<d.
Note in the unchained version, the first and last operands of the chained form
appear exactly once and all other operands appear twice.
n-ary operators can be composed of any of the relational operators <, >, ≤, ≥, =, ≠, ≈
and any of the set-relational operators ⊂, ⊆, ⊄, ⊈.
The operators can be mixed, so 0≤x<10 unchains to (0≤x)∧(x<10)
and the equivalent 10>x≥0 unchains to (10>x)∧(x≥0).
Similarly, {a}⊆{a, b}⊂{a, b, c} unchains to ({a}⊆{a, b})∧({a, b}⊂{a, b, c}).
2.4.3 Unary Operators
Examples of unary operators are
-x,
¬A
and
ln x.
See §2.10.2 for a summary of unary operations.
Figure 2.23 Prefix unary operators
When the operand comes after the operator, as in the
examples above, it is called a
prefix unary operator (Figure 2.23).
There are also
postfix unary operators,
written with the operand before the operator (Figure 2.24). One of these is the factorial
operator !, as in
n!. Another postfix unary operator is
°, the degree operator, as in
x °. (Simplifying an expression like
45 °
converts the operand to radians.) Matrix transpose is indicated by the
postfix
T
operator, as in
[(1, 2), (3, 4)] T,
and imaginary numbers are indicated by the postfix ⅈ operator
(see §2.7).
Figure 2.24 Postfix unary operators
Unary operators associate more closely than binary operators.
To illustrate the first sort of association, note the difference between
(x^2)°
and
x^2°. The former is
(x^2) °
while the latter is
x^2 °. Being a unary operator, albeit postfix, the operand 2 associates
more closely with ° than with the binary operator
^.
Postfix
operators associate more closely than prefix unary operators.
Thus -2° means .[-(2 °)].
If the operand of a prefix unary operator is an expression containing other
binary or postfix unary operators, the operand must be placed in parenthesis. For example,
-x^2
is different from
-(x^2). Similar logic applies in the case of
transcendental functions.
sin-x^2
is different from
sin-(x^2); the former displays as
sin -x^2.
Cast operators use keyboard- and formal-type notation
(see Figure 2.10)
as a postfix operator to specify a conversion. For example, a radial can be converted to a vector by placing the
vector type specifier after the radial. The radial (5, 30 °)ɽ, entered as (5,30°)r,
can be converted to a vector by the expression (5, 30 °)ɽʋ, entered as (5,30°)r v.
The result of simplification is (5⋅cos (ℼ/6), 5⋅sin (ℼ/6))ʋ. Although this example looks like
a tuple followed by two cast operators, the first of these (ɽ) indicates a radial value, leaving the
second (ʋ) as a cast operator. Another example reshapes a matrix by first casting it to a tuple:
[2⋅r+c|r∈0, 2|c∈0, 1]ʈ↑(2, 3) simplifies to [(0, 1, 2), (3, 4, 5)].
The matrix cast operator treats its operand as a list of row items. Thus (1,2,3)m produces
a column matrix, and (1,(2,3),4)m produces [(1, 0), (2, 3), (4, 0)].
Function references (see §2.5)
are indicated by placing a parameter list after a function identifier.
In some programming languages, applying a parameter list
to a function is called deproceduring.
Consistent with this, it is easy to see how the parameter
list can be considered a postfix operator.
Indexing (see §2.6)
is notationally similar to deproceduring, using brackets in place of parenthesis.
Figure 2.25 Bifix unary operators
Enclosures. Another kind of unary operator uses the closely allied mathematical notation
involving brackets of various sorts. Magnitude, floor and ceiling are unary
operations denoted by enclosing the operand in special symbols, as in |x|, ⌊x⌋ and ⌈x⌉.
Being neither prefix nor postfix, this kind of operator is called “bifix” because the operand
is positioned between two operator symbols.
For ease of entry, an alternate input form uses a right parentheses as the closing partner for ceiling and floor operators.
That is, ⌊x⌋ can be
entered as ⌊x).
Radicals are both unary and binary operators.
As a unary
operator,
√x
displays as
√x, as does
x^(1/2).
As a binary operator, 3√x displays as 3√x, as does x^(1/3).
3√x
can also be entered as
root(3,x).
Like exponentiation, binary √ is right associative, so 3√4√5 displays as 3√(4√5).
Note the difference between
√x+1
(entered as
√x+1) and
√(x+1)
(entered as
√(x+1)).
When the square root of a constant is simplified algebraically,
it is replaced by just the positive root and then only
if that value is an integer. If the expression was
intended to convey both positive and negative square roots, it should
have been written using the unary operator ±. If a decimal
value is required, the expression should be evaluated rather than simplified.
See §6.1 for a discussion on positive and negative roots.
Figure 2.26 Builtin functions
Builtin functions
with a single argument are treated as unary operators. There is no
need to code
sin(x)
to look like a function;
sin x
will do.
Transcendental functions are builtin and hence are treated as
unary operators. Thus sin x^2 applies the unary sin to
the argument x, then raises resulting primary to the power of 2.
Mathematicians use an alternative notation in which the power
appears as a superscript between the trigonometric function and its argument.
Thus the displayed form is sin x^2.
Trigonometric functions can also be entered in the alternative notation of
mathematics, with the exponent following the function name, as in
sin^2 x.
Note, however, the difference between
sin x^2
and
sin (x^2), which displays as
sin (x^2). This distinction is a consequence of parsing the parenthesized
argument as a primary.
Inverse trigonometric functions can also be entered using the
alternative notation, with -1 as the exponent.
arcsin x
and
sin^-1x
display as the equivalent
arcsin x. sin x^-1, however displays as sin x^-1, meaning 1÷sin x.